clear
[x,fs]=audioread('v_1.wav');
leftpoints=5;
rightpoints=5;
Fs=16000;
Fy=44100;
tx=1/Fs;
ty=1/Fy;
out=zeros(1,length(x));
frames=floor(length(x)/160);
printtmp=zeros(441,13);
for j=0:440
       for k=-6:6
           km=floor(j*ty/tx);
           dm=j*ty/tx-km;
           printtmp(j+1,k+7)=sinc(k+dm)*(0.54-0.46*cos(2*pi*(k+dm+6)/12));
           %outframe(j+1)=outframe(j+1)+sinc(k+dm)*x(xs+km-k)*(0.54-0.46*cos(2*pi*(k+dm+6)/12));
           %tmp=[tmp,k+dm];
       end
end
% cfilewriter('resample_16_441_k6.h', printtmp, "float", "resample_16_441_k6_f","w");
% cfilewriter('resample_16_441_k6.h', printtmp*128, "int8", "resample_16_441_k6_int8","a");
% cfilewriter('resample_16_441_k6.h', printtmp*2^15, "int16", "resample_16_441_k6_int16","a");

for i=2:frames-1
   xs=(i-1)*160;
   xe=i*160;
   outframe=zeros(1,441);
   %tmp=[];
   for j=0:440
       for k=-6:6
           km=floor(j*ty/tx);
           dm=j*ty/tx-km;
           outframe(j+1)=outframe(j+1)+printtmp(j+1,k+7)*x(xs+km-k);
           %outframe(j+1)=outframe(j+1)+sinc(k+dm)*x(xs+km-k)*(0.54-0.46*cos(2*pi*(k+dm+6)/12));
           %tmp=[tmp,k+dm];
       end
   end
   %plot(unique(tmp));
   out((i-1)*441+1:i*441)=outframe;
end
audiowrite('v_1out.wav',out,44100);

